﻿using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharp.Study.Test
{
    public class JsonTestNew
    {
        public static void Go()
        {
            List<UserOutput> users = new List<UserOutput>();
            UserOutput user = new UserOutput();
            user.Roles.Add(new RoleOutput());
            users.Add(user);
            var result = new PageResult<UserOutput>(users, 1, 10, 1);
            var settings = new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };
            string a = JsonConvert.SerializeObject(result, settings);
        }
    }

    public class PageResult<T>
    {
        /// <summary>
        /// 数据总数
        /// </summary>
        public int TotalCount { get; set; }
        /// <summary>
        /// 总页数
        /// </summary>
        public int PageCount { get; set; }

        /// <summary>
        /// 分页大小
        /// </summary>
        public int PageSize { get; set; }
        public int PageNo { get; set; }
        /// <summary>
        /// 数据集合
        /// </summary>
        public List<T> List { get; set; } = new List<T>();

        public PageResult(List<T> data, int pageNo, int pageSize, int totalCount)
        {
            List = data;
            PageNo = pageNo;
            PageSize = pageSize;
            TotalCount = totalCount;
            PageCount = pageSize <= 0 ? 0 : (int)Math.Ceiling((double)totalCount / pageSize);
        }
    }

    public class UserOutput
    {
        public string UserId { get; set; } = "";
        public string UUId { get; set; } = "";
        public string UserName { get; set; } = "";
        public string EmpNo { get; set; } = "";
        /// <summary>
        /// 0 是正常 2是待激活 -1是删除  1是冻结
        /// </summary>
        public int Status { get; set; }
        public string Mobile { get; set; } = "";
        public string Email { get; set; } = "";
        public int DepartmentId { get; set; }
        public string DepartmentName { get; set; } = "";
        public int DevSiteAdmin { get; set; } = 0;
        public int UseSiteAdmin { get; set; } = 0;
        public List<RoleOutput> Roles { get; set; } = new List<RoleOutput>();
        public int IsDeveloper { get; set; } = 0;
        public int Director { get; set; }//是否是主管
    }

    public class RoleOutput
    {
        public string UserId { get; set; } = "";
        public int RoleId { get; set; }

        public string Code { get; set; } = "";

        public string Name { get; set; } = "";

        public int Sort { get; set; }

        public int RoleGroupid { get; set; }
    }
}
